<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8">
	<meta name="author" content="wangbo">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		let name = '张三';
		// 等同于
		let obj = {
			name: name
		}
		var o = {
			method() {
				return "Hello!";
			}
		};
		// 等同于
		// var o = {
		// 	method: function () {
		// 		return "Hello!";
		// 	}
		// };
		console.log(o);

		var cart = {
			_wheels: 4,
			get wheels() {
				return this._wheels;
			},
			set wheels(value) {
				if (value < this._wheels) {
					throw new Error('数值太小了！');
				}
				this._wheels = value;
			}
		}

		// 方法一
		obj.foo = true;
		obj['a' + 'bc'] = 123;
		// 方法二
		let propKey = 'foo';
		let obj = {
			[propKey]: true,
			['a' + 'bc']: 123
		};

		var lastWord = 'last word';
		var a = {
			'first word': 'hello',
			[lastWord]: 'world'
		};
		a['first word'] // "hello"
		a[lastWord] // "world"
		a['last word'] // "world
	</script>
</body>

</html>